package com.iflytek.aisol.audit.iflytek.strategy.manage.mapper;


import cn.hutool.core.bean.BeanUtil;
import com.iflytek.aisol.audit.iflytek.strategy.manage.constant.ChannelType;
import com.iflytek.aisol.audit.iflytek.strategy.manage.entity.ChannelConfig;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * CLassName: channelConfigMapper
 * Description:
 * Author: wuzhixiang
 * Date: 2024-12-28 16:08
 * Version: 1.0
 *
 * @author hswang7
 */
@Repository
public interface ChannelConfigMapper extends JpaRepository<ChannelConfig, Long> {

    @Query("SELECT s FROM ChannelConfig s WHERE s.channelId = :channelId " +
            "AND s.deleted = 0 ORDER BY s.version DESC")
    List<ChannelConfig> findWithChannelIdAndNoDeleteAndVersionMax(@Param("channelId")String channelId);


    @Query("SELECT cc FROM ChannelConfig cc WHERE (:channelId IS NULL OR cc.channelId = :channelId) " +
            "AND (:version IS NULL OR cc.version = :version) " +
            "AND (:deleted IS NULL OR cc.deleted = :deleted)" +
            "AND (:templateName IS NULL OR cc.templateName = :templateName)")
    Page<ChannelConfig> findPage(@Param("channelId") String channelId,
                                 @Param("version") Long version,
                                 @Param("deleted") Long deleted,
                                 @Param("templateName") ChannelType templateName,
                                 Pageable pageable);

}
